home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 52
/
Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso
/
Aminet
/
util
/
libs
/
ttengine.lha
/
ttengine-4.1
/
Developer
/
autodocs
/
ttengine.doc
Wrap
Text File
|
2002-09-29
|
24KB
|
630 lines
TABLE OF CONTENTS
ttrender.library/background
ttrender.library/font_database
ttrender.library/TT_CloseFont
ttrender.library/TT_GetAttrsA
ttrender.library/TT_OpenFontA
ttrender.library/TT_SetAttrsA
ttrender.library/TT_SetFont
ttrender.library/TT_Text
ttrender.library/TT_TextExtent
ttrender.library/TT_TextFit
ttrender.library/TT_TextLength
ttrender.library/background ttrender.library/background
PURPOSE
The library is fast, AmigaOS friendly TrueType render engine. It has
nothing to do with Amiga outline font system. This system has a lot of
limitations which make it useless for high speed and quality text output.
If someone wants an integration of TrueType with AmigaOS bullet.library
like outline font system, should consider using ttf.library. This library
opens TrueType font by itself and renders high quality glyphs directly
into any RastPort.
FREETYPE2 BASED
The render engine of the library is based on FreeType2 project
(http://www.freetype.org). This version of ttrender.library uses 2.0.9
FreeType build.
REQUIREMENTS
- OS 3.0+.
- 68020 or better processor.
- for antialiased output graphics board with at least 15-bit screenmode
and RTG system: CyberGraphX 3.x+ or Picasso96 2.x+.
FEATURES
The library expands FreeType functionality making usage of TrueType fonts
easy and comfortable. Below you can find key features:
- renders whole strings (not single glyphs) with kerning.
- antialiasing to any (not neccesarily uniform color) background.
- system compatible output to any (including planar) RastPort.
- supports JAM1. JAM2, INVERSVID, COMPLEMENT RastPort modes.
- supports 8-bit to Unicode mapping with "ENV:ttfcodepage" table
compatible with ttf.library.
- allows for direct 16-bit Unicode string rendering.
- easy to use, taglist based API almost identical to graphics.library
font API.
- efficient system-wide glyph cache system.
CACHE SYSTEM
The library uses my own (not that experimental FreeType one) cache system
speeding up strings rendering alot. The cache is system-wide, it means it
is common to every application using ttrender.library. Only used glyphs of
given font face are cached. If the library encounters cache miss, missing
glyph is loaded and rasterized on the fly. Cache system is totally
transparent to the library user, so there are no cache functions in the
library API. Cache uses one single Exec memory pool avoiding memory
fragmentation.
ttrender.library/font_database ttrender.library/font_database
GENERAL INFORMATION
'ttengine.database' is a plain text file (placed in 'ENV:' directory)
containing informations about TrueType fonts available in the system.
There is no tool (yet) to automatically generate it, the database have to
be written by hand. Every line contains one keyword followed by parameter
value. Name and value can be separated by space(s) or equality sign,
exactly the same as shell command parameters (to say more - database is
parsed by the same ReadArgs() system call as shell command parameters
are). Parameter values containing spaces should be quoted. Here are some
examples:
FAMILY Tahoma
FAMILY=Times
FAMILY = "Times New Roman"
FAMILY "Weird Font"
KEYWORDS
FAMILY - defines the name used for font opening. All variants of the font
(italic, bold, black, heavy, light, demi etc.) will have the same family
name. Family names (and aliases described below) are case insensitive.
ALIAS - defines another name for the same family. It generally has three
purposes:
1. Similar names for the same font, like "Times", "TimesNewRoman" and
"Times New Roman".
2. One replacement font for some very similar ones, for example
"Helvetica" and "Switzerland" can be aliased to "Arial".
3. Generic names like "default", "serif", "sans-serif", "monospaced". An
application can request generic name without specific family name, or
generic font can be used as a fallback if given name can't be found in
the database. For example you can alias "monospaced" to "Courier", and an
application (be it CSS compatible HTML viewer) can request
'LucidaConsole, monospaced'. If there is no LucidaConsole font in the
system, Courier will be used. The same way you can alias any font to any
other, for example Times to Arial, this makes not much sense however.
'default' font can be used as a last resort.
FILE - defines single TrueType font file and its attributes, which are:
FILE itself - defines a path to the font file. Font files can be placed
anywhere in the filesystem(s). There is no default value for the
attribute, it must be given explicitly.
WEIGHT - defines font weight in Cascading Style Sheets manner, where 0
means the lightest and 999 means the heaviest weight. 400 is typical
value for normal weight, 700 for bold. Default value is 400 (normal).
STYLE - "regular" or "italic" for italic and oblique faces. Default
value is "regular".
SMOOTHSMALL - controls antialiasing of small sizes. Any sizes smaller or
equal to SMOOTHSMALL will be antialiased. Note: can be overriden by
application. Default value is 9.
SMOOTHBIG - controls antialiasing of big sizes. Any sizes bigger or
equal to SMOOTHBIG will be antialiased. Note: can be overriden by
application. Default value is 18.
Every FILE is automatically added to the nearest FAMILY defined above
in the database file. Every ALIAS or FILE placed before the first
FAMILY is rejected quietly.
COMMENTS
You can place any full-line comments in the file starting a line with
hash or semicolon. End-line comments are not supported.
ttrender.library/TT_CloseFont ttrender.library/TT_CloseFont
NAME
TT_CloseFont -- Closes TrueType font. (V4)
SYNOPSIS
TT_CloseFont (font)
A0
VOID TT_CloseFont (APTR);
FUNCTION
Closes font opened by TT_OpenFontA()
INPUTS
font - the result of TT_OpenFontA(). Can be NULL, no action is taken
in the case.
RESULT
none
NOTES
BUGS
SEE ALSO
TT_OpenFontA()
ttrender.library/TT_GetAttrsA ttrender.library/TT_GetAttrsA
NAME
TT_GetAttrsA -- Gets current font and render engine attributes (V4).
SYNOPSIS
count = TT_GetAttrsA (rastport, taglist)
A1 A0
ULONG TT_GetAttrsA (struct RastPort*, struct TagItem*);
count = TT_GetAttrs (rastport, Tag1, ...)
ULONG TT_GetAttrs (struct RastPort*, Tag, ...);
FUNCTION
Gets current font or render engine attributes for given RastPort. The
value of every attribute is written to an ULONG pointed by ti_Data
field of the TagItem. Here is a list of attributes:
TT_Antialias - Current state of an antialias switch (on, off or
auto).
TT_Ascender - This is a distance (in pixels) between the baseline
and top elements of the font (typically these elements are accents
of capital letters). NOTE: many shareware TT fonts have wrong ascen-
der value.
TT_Descender - This is a distance (in pixels) between the baseline
and bottom elements of the font (typically in letters 'p', 'q', 'g'
etc.). NOTE: many shareware TT fonts have wrong descender value.
Descender value is typically negative (as bottom elements usually
are placed below the baseline).
TT_FontName - full font name as found in the font file. Pointer to a
NULL-terminated string is written. This string is localized if the
font file contains names in different languages. Language
precedence is loaded from "Preferred languages" table of
locale.library.
TT_FamilyName - font family name as found in the font file. Pointer
to a NULL-terminated string is written. This string is localized if
the font file contains names in different languages. Language
precedence is loaded from "Preferred languages" table of
locale.library.
TT_SubfamilyName - font subfamily name (typically describing font
variant like "italic" or "bold") as found in the font file. Pointer
to a NULL-terminated string is written. This string is localized if
the font file contains names in different languages. Language
precedence is loaded from "Preferred languages" table of
locale.library.
TT_Transparency - returns actual transparency setting.
NOTE: TTFA_Ascender and TTFA_Descender are guarranted to fulfill
following formula: ascender - descender = font height.
INPUTS
rastport - attributes associated with this RastPort will be returned.
taglist - the list of attributes.
RESULT
counter - the count of recognized tags.
NOTES
Data returned are valid only until TT_CloseFont() call.
BUGS
SEE ALSO
TT_OpenFontA(), TT_SetAttrsA()
ttrender.library/TT_OpenFontA ttrender.library/TT_OpenFontA
NAME
TT_OpenFontA -- Opens TrueType font. (V4)
SYNOPSIS
font = TT_OpenFontA (taglist)
A0
APTR TT_OpenFontA (struct TagItem*);
font = TT_OpenFont (Tag1, ...)
APTR TT_OpenFont (Tag, ...);
FUNCTION
Opens a TrueType font preparing it to use with any RastPort. Font may
be specified directly as a path to "*.ttf" file, or indirectly via
set of attributes, database search will be performed for this set and
best matching font will be opened. It is graphics.library OpenFont()
counterpart but taglist is used instead TextAttr structure.
INPUTS
taglist - a list of tags containing requested font attributes.
Following tags are recognized:
TT_FontFile - this tag is a pointer to string containing a full
path to TrueType font file to be opened. This tag allows for
overriding database search and match. That means
TT_FamilyTable, TT_FontStyle and TT_FontWeight are ignored if
TT_FontFile is specified. Useful for opening application
specific fonts, containing for example musical notes or some
other kind of symbols. This tag has no default value.
TT_FamilyTable - NULL-terminated table of pointers to font family
names from the most desired to the last resort fallback. It is
intended for easy implementing things like HTML 'FONT FACE'
attribute. You can use real family names here, as well as
generic names: 'serif', 'sans-serif', 'monospaced', 'cursive',
'fantasy', and 'default', especially useful as a fallbacks.
Family names are case insensitive.
The default value for the tag is {"default", NULL};
TT_FontSize - font size in pixels defined as the distance between
baselines of two following text lines. The default value for
this tag is 14 pixels.
TT_FontStyle - there are two styles defined:
TT_FontStyle_Regular (default),
TT_FontStyle_Italic.
TT_FontWeight - defined with Cascading Style Sheets manner as a
number from 0 (the lightest face) to 999 (the heaviest face).
You can use TT_FontWeight_Normal (equal to 400) and
TT_FontWeight_Bold (equal to 700) shortcuts.
TT_FontWeight_Normal is the default value.
RESULT
success - font pointer (for use with TT_SetFont() and TT_CloseFont())
if the font has been opened successfully, NULL
otherwise. This function can fail for four reasons:
1. There is no matching face in the database (NOTE: even
'default' can fail if not defined in the database!)
2. File not found or malformed.
3. Zero font size.
4. No memory for requested (too big?) size.
NOTES
BUGS
SEE ALSO
TT_SetFont(), TT_CloseFont(), font_database
ttrender.library/TT_SetAttrsA ttrender.library/TT_SetAttrsA
NAME
TT_SetAttrsA -- Sets rendering engine and font attributes. (V4)
SYNOPSIS
count = TT_SetAttrsA (rastport, taglist)
A1 A0
ULONG TT_SetAttrsA (struct RastPort*, struct TagItem*);
count = TT_SetAttrs (rastport, Tag1, ...)
ULONG TT_SetAttrs (struct RastPort*, Tag, ...);
FUNCTION
Sets render engine settings for given RastPort. Every following
TrutType render and metrics calls for this RastPort will use these
settings. Here is a list of attributes:
TT_ColorMap - (struct ColorMap*) - ColorMap used to convert pen
number to RGB color value.
TT_Screen - (struct Screen*) - useful shortcut for TTA_ColorMap,
automatically sets screen ColorMap.
TT_Window - (struct Window*) - useful shortcut for TTA_ColorMap,
automatically sets window ColorMap.
TT_Antialias - (BOOL) - controls antialiasing (on, off or
automatic):
TTA_Antialias_Off - turns antialias off
TTA_Antialias_On - turns antialias on
TTA_Antialias_Auto (default) - antialias state depends on font
size. Typically sizes of 9 or less pixels are antialiased, sizes
from 10 to 19 pixels are not antialiased, sizes of 20 of more
pixels are antialiased. These settings can be changed in the font
database separately for every font face.
TT_Encoding - selects font encoding table to be used:
TT_Encoding_Default - loads encoding table from "ENV:ttfcodepage"
file, compatible with ttf.library. If no such file is found,
ISO-8859-1 encoding (Amiga default) is used.
TT_Encoding_Unicode - strings are interpreted as tables of 16-bit
Unicode characters.
TT_Encoding_ISO8859_1 - ISO-8859-1 (Western Europe).
TT_Encoding_ISO8859_2 - ISO-8859-2 (Eastern and Central Europe).
TT_Transparency - Allows for rendering transparent text (the
background shines through the text). 0 value means no transparency
(this is the default), 255 is maximum transparency.
INPUTS
rastport - attributes will be set for this RastPort.
taglist - the list of attributes.
RESULT
counter - the count of recognized tags.
NOTES
BUGS
SEE ALSO
TT_OpenFontA(), TT_Text(), TT_GetAttrs()
ttrender.library/TT_SetFont ttrender.library/TT_SetFont
NAME
TT_SetFont -- Sets TrueType font for a RastPort. (V4)
SYNOPSIS
TT_SetFont (rastport, font)
A1 A0
VOID TT_SetFont (struct RastPort*, APTR);
FUNCTION
Sets a font previously opened with TT_OpenFontA() for use with given
RastPort. All further calls of text rendering or metrics function for
this RastPort will use font set.
INPUTS
rastport - The font will be set for this RastPort.
font - Pointer returned by TT_OpenFontA(). May be NULL, function
returns immediately in the case.
RESULT
none
EXAMPLE
/* use two fonts to render in one RastPort */
APTR times, arial;
times = TT_OpenFont(
TT_FamilyTable, (ULONG){"Times", "serif", "default", NULL},
TT_FontSize, 26,
TAG_END);
arial = TT_OpenFont(
TT_FamilyTable, (ULONG){"Arial", "sans-serif", "default", NULL},
TT_FontSize, 22,
TT_FontWeight, TT_FontWeight_Bold,
TAG_END);
if (times && arial)
{
SetAPen(win->RPort, 1);
SetDrMd(win->RPort, JAM1);
Move(win->RPort, 100, 100);
TT_SetAttrs(win->RPort, TTA_Window, win, TAG_END);
TT_SetFont(win->RPort, times);
TT_Text(win->RPort, "Times 26 points", 15);
TT_SetFont(win->RPort, arial);
TT_Text(win->RPort, "Arial 22 points", 15);
}
if (arial) TT_CloseFont(arial);
if (times) TT_CloseFont(times);
NOTES
Function can fail silently if:
1. RastPort pointer is NULL.
2. Font pointer is NULL.
3. Font pointer is not found on opened fonts list (it means the pointer
was not obtained as a result of TT_OpenFontA() call.
BUGS
SEE ALSO
TT_OpenFontA(), TT_SetAttrsA(), TT_CloseFont()
ttrender.library/TT_Text ttrender.library/TT_Text
NAME
TT_Text -- Renders string into RastPort. (V4)
SYNOPSIS
TT_Text (rastport, string, count)
A1 A0 D0
VOID TT_Text (struct RastPort*, APTR, ULONG);
FUNCTION
Renders the string using current ttrender.library settings, and
current RastPort settings (pen, drawmode). String is rendered at
current RastPort (x, y) position, where 'y' means position of font
baseline. String is converted to Unicode according to
current (set by TT_SetAttrs()) encoding table.
INPUTS
rastport - Target RastPort for rendering.
string - String to render to (need not to be NULL terminated).
count - How many characters to render (note that NULL code will
be rendered as well).
RESULT
none
EXAMPLE
/* write a text with pen 1 and transp. background at (100, 100) */
/* rendering is done to a system window */
SetAPen(win->RPort, 1);
SetDrMd(win->RPort, JAM1);
Move(win->RPort, 100, 100);
TT_SetAttrs(win->RPort, TTA_Window, win, TAG_END);
TT_Text(win->RPort, "some text", 9);
NOTES
BUGS
SEE ALSO
TT_OpenFontA(), TT_SetAttrsA()
ttrender.library/TT_TextExtent ttrender.library/TT_TextExtent
NAME
TT_TextExtent -- Determine raster extent of text data. (V4)
SYNOPSIS
TT_TextExtent (rastport, text, count, extent)
A1 A0 D0:16 A2
VOID TT_TextExtent (struct RastPort*, APTR, WORD,
struct TextExtent*);
FUNCTION
Computes dimensions and coordinates of smallest rectangle containing
on the whole given text rendered with current settings. TextExtent
structure fields have following meaning:
te_Width - Horizontal advance of RastPort pen position. The same as
TT_TextLength() call result.
te_Height - Just current font height.
te_Extent.MinX - The horizontal distance from text start point to the
leftmost pixel rendered. May be negative, it means that some
pixels will be plotted before the start point.
te_Extent.MaxX - The horizontal distance from text start point to the
rightmost pixel rendered.
te_Extent.MinY - The vertical distance from text start point to the
topmost pixel rendered. Always negative, do not neccesarily equal
to -TTFA_Ascender.
te_Extent.MaxY - The vertical distance from text start point to the
lowermost pixel rendered. Typically positive if anything is to be
drawn below the baseline.
INPUTS
rastport - this rastport settings (font, size, style etc.) will be
used for calculations.
text - a string (not neccesarily NULL-terminated) to compute the
rectangle for.
count - length of the string in characters.
extent - pointer to TextExtent structure - it will be filled with
data.
RESULT
No retrurn value. TextExtent structure is filled with data.
NOTES
This function is almost identical to graphics.library/TextExtent().
It even receives parameters in the same registers.
Do not assume neither horizontal extents sum up to te_Width, nor
vertical ones sum up to font height.
BUGS
SEE ALSO
TT_OpenFontA(), graphics.library/TextExtent()
ttrender.library/TT_TextFit ttrender.library/TT_TextFit
NAME
TT_TextFit -- Count characters that will fit in a given extent. (V4)
SYNOPSIS
characters = TT_TextFit (rastport, string, count, extent,
A1 A0 D0:16 A2
constr_extent, direction, width, height)
A3 D1 D2 D3
ULONG TT_TextFit (struct RastPort*, APTR, UWORD, struct TextExtent*,
struct TextExtent*, WORD, UWORD, UWORD);
FUNCTION
Computes how many characters of given NULL-terminated string rendered
with current settings will fit into given extent. Also calculates an
extent for this fitting part of the string. Function can fit from the
beginning of the string to the right, or from the end of the string
to the left. If 'constr_extent' is non NULL, string is fitted only
against it, constraining 'width' and 'height' are ignored.
INPUTS
rastport - calculations will be performed using this rastport
settings (font, size, styles etc.).
string - A string (not neccesarily NULL-terminated) to fit.
count - string lenght in characters.
extent - Pointer to TextExtent structure - it will be filled with
dimensions of fitted part of the string. May be filled with all
zeros if no fit is possible at all (e.g. height is to small).
constr_extent - Pointer to already filled TextExtent structure. Part
of the string will fit into this extent. It is not modified by
function. May be NULL, 'width' and 'height' will be used as
constraints.
direction - When equal to 1 string will be fitted starting from it's
beginning to the rigth. When equal to -1, string will be fitted
starting from it's end to the left.
width - If 'constr_extent' is NULL, the string width will be compared
with this parameter. Ignored otherwise.
height - If 'constr_extent' is NULL, the string height will be
compared with this parameter. Ignored otherwise.
RESULT
characters - the length of fitting string part. May be zero if no fit
found.
NOTES
This function is almost identical to graphics.library/TextFit().
It even receives parameters in the same registers.
Do not assume neither horizontal extents sum up to te_Width, nor
vertical ones sum up to font height (in returned extent).
BUGS
SEE ALSO
TT_OpenFontA(), graphics.library/TextFit()
ttrender.library/TT_TextLength ttrender.library/TT_TextLength
NAME
TT_TextLength -- Gets string length in pixels (V4).
SYNOPSIS
length = TT_TextLength(rastport, string, count)
A1 A0 D0
ULONG TT_TextLength (struct RastPort*, APTR, ULONG);
FUNCTION
Calculates the pixel width of given string written with current font.
Takes kerning into account. String will be mapped to Unicode using
current encoding.
INPUTS
rastport - render engine and font settings for this RastPort will be
used for calculations.
string - the length of this string will be calculated.
count - the string lenght in characters.
RESULT
length - the length of the string in pixels.
NOTES
BUGS
SEE ALSO
TT_Text(), TT_OpenFontA()